import axios from 'axios'
import store from '@/store'
import { Message } from 'element-ui'
// import { getToken } from '@/utils/auth'
const request = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 5000
})

request.interceptors.request.use(function(config) {
  const token = store.getters.token
  if (token) {
    config.headers.Authorization = token
  }
  return config
},
function(err) {
  return Promise.reject(err)
})

request.interceptors.response.use(function (response) {
  return response.data
}, function (err) {
  Message.error(err.response.data)
  return Promise.reject(err)
})

export default request
